/*
   Copyright 2011 James Bowling

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package com.armedia.dctm.constraints.test;

import org.junit.Test;

import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfList;
import com.documentum.fc.common.IDfAttr;
import com.documentum.fc.common.IDfList;
import com.documentum.fc.common.IDfValue;

public class CallDocbasicTestCase extends AbstractTestCase {

	@Test
	public void test() throws DfException {
		IDfSession session = getSession(); 
		IDfCollection coll = null;
		IDfList args = new DfList();
		IDfList datatypes = new DfList();;
		IDfList values = new DfList();
		
		String docbaseName=session.getDocbaseName();
		StringBuffer params=new StringBuffer();
		params.append("'");
		params.append("-docbase " + docbaseName);
//		params.append(" -merge_type " + merge_Type);
		params.append("'");

		args.appendString("METHOD");
		args.appendString("SAVE_RESULTS");
		args.appendString("ARGUMENTS");

		datatypes.appendString("S");
		datatypes.appendString("B");
		datatypes.appendString("S");
		values.appendString("Len('0123456789')=10");
		values.appendString("T");
		values.appendString(params.toString());
		
		try{
			//call the method
			coll = session.apply(null, "DO_METHOD", args, datatypes, values); 
			while (coll.next()) {
				IDfAttr theAttr = coll.getAttr(0);
				String theAttrName = theAttr.getName();
				System.out.println("Attr in collection is called: " + theAttrName);
				IDfValue theValue = coll.getValueAt(0);
				System.out.println("Value is: " + theValue.asInteger());
			} 		
			coll.close();
		} finally {
			if (coll != null) {
				coll.close();
			}
		}
		
	}
}
